<template>
  <div class="bagPay">
    <div class="mian">
      <div class="content">
        <div class="title">
          <i class="iconfont icon-guanbi" @click="isShowbagPay"></i>
          确认支付
        </div>
        <p>挖取人工费.包装费.邮费（500元）</p>
        <div class="item" @click="clickPay">
          <img src="../img/alipay.png" alt srcset>
        </div>
        <div class="item" v-if="Judge" @click="clickWxPay">
          <img src="../img/wx.png" alt srcset>
        </div>
      </div>
    </div>
    <div id="alipay"></div>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import {
  isAndroidOrIos,
  getGuid,
  isWeixin,
  openUrl,
  openUrlPay
} from "../../../utils/index";
import { hex_md5 } from "../../../utils/md5";
import { webpay } from "../../../api";
import { pay } from "../../../utils/wxPay";

export default {
  data() {
    return {
      zyGameID: localStorage.zyGameID,
      Judge: window.Judge
    };
  },
  methods: {
    ...mapActions(["isShowbagPay"]),
    clickWxPay() {
      let PayType = "2";
      if (isAndroidOrIos().isAndroid) {
        PayType = "1";
      } else if (isAndroidOrIos().isiOS) {
        PayType = "0";
      }
      if (window.Judge) {
        pay("wxpay", PayType, 12);
      }
    },
    clickPay() {
      let PayType = "2";
      if (isAndroidOrIos().isAndroid) {
        PayType = "1";
      } else if (isAndroidOrIos().isiOS) {
        PayType = "0";
      } else {
        PayType = "2";
      }
      let keystr = hex_md5(this.zyGameID + "," + PayType + "," + "12");
      webpay({
        // GameID: this.zyGameID,
        GameID: this.zyGameID,
        ProductID: "12",
        PayType: PayType,
        SinKey: keystr
      })
        .then(res => {
          let html = res.data.replace(/^.*?:"|\"}$/gi, "");
          document.getElementById("alipay").innerHTML = html;
          document.forms["alipaysubmit"].submit();
        })
        .catch(err => {
          //alert("err");
        });
    }
  }
};
</script>
<style lang="stylus" scoped>
.bagPay {
  width: 100%;
  height: 100%;
  background: rgba(0, 1, 3, 0.9);
  position: fixed;
  left: 0;
  top: 0;

  .mian {
    width: 7.04rem;
    // height: 4.88rem;
    background: #FFF;
    border-radius: 0.2rem;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);

    .content {
      width: 6.63rem;
      margin: 0 auto;

      p {
        text-align: center;
      }

      .title {
        margin: 0.15rem auto 1rem auto;
        line-height: 1rem;
        text-align: center;
        border-bottom: 1px solid rgba(137, 137, 137, 1);
        position: relative;

        i {
          position: absolute;
          left: 0;
          top: 2px;
        }
      }

      .item {
        width: 6.13rem;
        height: 1.58rem;
        margin: 0.8rem auto;

        img {
          width: 100%;
        }
      }
    }
  }
}
</style>
